﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Veteran_cms.Models;
namespace Veteran_cms.Controllers
{
    public class ManageAboutController : BaseController
    {
        Veterandb ctx = new Veterandb();
        //
        // GET: /ManageAbout/

        public ActionResult IndexAbout()
        {
            var about = (from aboutus in ctx.abouts where aboutus.about_id != 0 select aboutus).SingleOrDefault();
            if (about != null)
                return View(about);
            else
            {
                about = new about();
                return View(about);
            }   
        }
        [HttpPost]
        public ActionResult UpdateToAbout(int id, FormCollection frm)
        {
            try
            {
                //if (!IsAuthenticateAdmin())
                //    return RedirectToAction("LogOn", "DashBoard");

                var about = (from aboutus in ctx.abouts where aboutus.about_id == id select aboutus).SingleOrDefault();
                if (about != null){
                    about.title = frm["title"];
                    about.content = frm["content"];
                    UpdateModel(about);
                    ctx.SaveChanges();
                    return RedirectToAction("IndexAbout");
                }
                else {
                    about = new about();
                    about.title = frm["title"];
                    about.content = frm["content"];
                    ctx.AddToabouts(about);
                    ctx.SaveChanges();
                    return RedirectToAction("IndexAbout");
                }
            }
            catch
            {
                return View();
            }
        }
    }
}
